<template>
  <div>
    <h3 @click="openWeapp">跳到小程序</h3>
    traceId: {{ traceId }}
  </div>
</template>

<script>
import qs from 'querystring';
export default {
  name: "Demo3Aboutview",
  props: ["traceId"],
  data() {
    return {
      pageInfo: null,
    };
  },

  created() {
    this.pageInfo = JSON.parse(window.localStorage.getItem("pageInfo"));
    console.log(window.localStorage.getItem("bizType"));
  },
  async mounted() {
    // 配置云函数
    await this.configureCloud();
  },

  methods: {
    async openWeapp() {
      const obj = {
        qrCodeType: "oneToone",
        keyType: "101",
        scene: "test0",
        bid: this.pageInfo.bid,
        sid: this.pageInfo.sid,
        reffer: this.pageInfo.reffer,
        channel: this.pageInfo.channel,
        oneId: true,
        isRisk: false,
        bizType: window.localStorage.getItem("bizType"),
        phone: this.$route.query.phone,
        traceId: this.traceId,
      };
      let options = qs.stringify(obj)
      const c = window.c;
      const res = await c.callFunction({
        name: "public",
        data: {
          action: "getUrlScheme",
          options,
        },
      });
      console.log(res.result.openlink);
      // window.location.href = res.result.openlink;
    },

    async configureCloud() {
      const c = new cloud.Cloud({
        // 必填，表示是未登录模式
        identityless: true,
        // 资源方 AppID
        resourceAppid: "wx1d5876465bcfddb3",
        // 资源方环境 ID
        resourceEnv: "xcx-psbns",
      });
      await c.init();
      window.c = c;
      console.log(window.c);
    },
  },
};
</script>

<style lang="scss" scoped></style>
